import pickle 

FILTER_SRV = ['Twitter']
def pickleReader():
    fileToRead = open("all_store.backup")
    
    try:
        while True:
            data = pickle.load(fileToRead)
            yield data
    except:
        print "Completed Reading file" 
        return

def getTwitterUser(someText):
    if(someText.find("@") == -1):
        return ''
    else:
        if(len(someText[someText.find('@')+1:].split()) > 0):
            return someText[someText.find('@')+1:].split()[0]
        else:
            return ''

def parseFeed(currentFeed):
    for eachEntry in currentFeed['entries']:
        if(eachEntry['service']['name'] in FILTER_SRV or FILTER_SRV[0] == "*"):
                userInteraction = getTwitterUser(eachEntry['title'])
                if(userInteraction != ''):
                    print userInteraction
    return 

if __name__ == "__main__":
    pickleStream = pickleReader()
    
    for eachFeed in pickleStream:
        parseFeed(eachFeed)
